package com.qf.spring.mybatis;


import com.qf.spring.mybatis.mapper.DepartmentMapper;
import com.qf.spring.mybatis.pojo.TDepartments;
import com.qf.spring.mybatis.service.DepartmentService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.Random;

@RunWith(SpringJUnit4ClassRunner.class)
//指定spring的配置文件的位置，就不需要创建context对象了
@ContextConfiguration("classpath:applicationContext.xml")
public class test {
//    private DepartmentMapper departmentMapper;
//@Autowired
//    public void setDepartmentMapper(DepartmentMapper departmentMapper) {
//        this.departmentMapper = departmentMapper;
//    }
    private DepartmentService departmentService;
//    @Test
//    public void  test1(){
//        TDepartments departments=departmentMapper.findById(2);
//        System.out.println(departments);
//    }
@Autowired
    public void setDepartmentService(DepartmentService departmentService) {
        this.departmentService = departmentService;
    }

    @Test
public void  test1(){
    TDepartments departments=departmentService.findById(2);
    System.out.println(departments);
}
    @Test
    public void  test2(){
        TDepartments tDepartments = new TDepartments();
        tDepartments.setName("谭鱼头");
        tDepartments.setLocation("虎口");
//        if (new Random().nextBoolean()){
//            int i = 1/0;
//        }
        departmentService.insertDept(tDepartments);
        if (new Random().nextBoolean()){
            int i = 1/0;
        }
    }
}
